package com.adayo.memoryfree.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;


import com.adayo.memoryfree.R;
import com.adayo.memoryfree.base.AbsListAdapter;
import com.adayo.memoryfree.bean.MenuBean;

import org.xutils.view.annotation.ViewInject;
import org.xutils.x;

import java.util.List;

/**
 * Created by M02323 on 2017/3/28.
 */

public class MenuAdapter extends AbsListAdapter<MenuBean> {

	public MenuAdapter(Context context, List<MenuBean> datas) {
		super(context, datas);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = layoutInflater.inflate(R.layout.item_menu, parent, false);
			x.view().inject(holder, convertView);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		MenuBean menu = datas.get(position);
		holder.ivIcon.setImageBitmap(menu.getIcon());
		//x.image().bind(holder.ivIcon, "url", options); //加载url图片
		holder.tvName.setText(menu.getName());
		return convertView;
	}

	class ViewHolder {
		@ViewInject(R.id.iv_icon)
		ImageView ivIcon;
		@ViewInject(R.id.tv_name)
		TextView tvName;
	}
}
